import Vue from 'vue'
import Vuex from 'vuex'
import comment from './modules/comment'
// import * as types from './types' // 一次性导入所有
import {
  // getters as gtypes,
  // actions as atypes,
  mutations as mtypes
} from './types' // 按需导入

Vue.use(Vuex)

const state = {
  a: 1
}

const getters = {
  getterA (state) {
    return state.a
  }
}

const mutations = {
  updateA (state, payload) {
    state.a = payload
  }
}

const actions = {
  updateA (ctx, payload) {
    // ctx.commit('updateA', payload) // 这里容易敲错，而且项目中有可能有很多地方调用，如果以后要修改，那就灾难
    // ctx.commit(types.mutations.updateA, payload) // 对应 import * as types from './types' 导入语法
    ctx.commit(mtypes.updateA, payload) // 对应 import { mutations as mtypes } from './types' 导入语法
  }
}
const modules = {
  comment
}

const store = new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
  modules
})

export default store
